package top.blackr.folivora.common.pay.refund;

import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import top.blackr.folivora.common.pay.exception.RefundException;

import java.util.Map;

/**
 * 退款工厂
 *
 * @author BlackR
 */

@Component
@AllArgsConstructor
public class RefundFactory {

    private final Map<String, RefundStrategy<?>> refundServiceMap;

    @SuppressWarnings("unchecked")
    public <R extends RefundStrategy<?>> R getRefundStrategy(String refundStrategyName) {
        RefundStrategy<?> strategy = refundServiceMap.get(refundStrategyName);
        if (strategy == null) {
            throw new RefundException("暂不支持该退款策略");
        }
        return (R) strategy;
    }
}
